package com.zxl.responsibilitychain; //责任链模式COR

/**
 * @Author:zxl
 * @Date: 2023/8/11
 * 责任链模式COR（Chain of Responsibility Pattern）
 * 用『责任链模式』来优化 参数多重校验，非常优雅！
 * 1 正式开始干业务逻辑之前，先一堆的if判断，一共写了N个验证，验证OK后才执行下面的逻辑，error直接return
 *
 * 2
 */
public class Test {

    public static void main(String[] args) {
        User user = new User("z4", "123456", "管理员");

        Handler.Builder builderChina = new Handler.Builder();

        //链式编程，谁在前-谁在后看的清清楚楚
        builderChina.addHandler(new ValidateHandler())
                .addHandler(new LoginHandler())
                .addHandler(new AuthHandler());

        builderChina.build().doHandler(user);

        new BusinessLogicHandler().doBiz(user);

    }
}
